interface KeyPair<T, U> {
    key: T,
    value: U
}

let obj1: KeyPair<number, string> = {key: 10, value: 'ty'}
let obj2: KeyPair<string, number> = {key: 'hj', value: 67}

// 约束泛型
function IWithEcio<T>(arr: T[]): T[] { 
    console.log(arr.length)
    return arr
}

const arr = IWithEcio([2,3,5]) // 只能数组


interface IWithLength {
    length: number
}
// 约束泛型，主要是使用interface
function IWithLength<T extends IWithLength>(arg: T): T {
    console.log(arg.length)
    return arg
}
// 包含length方法,，可以是多个类型
const arr1 = IWithLength('hsdf')
const obj = IWithLength({length: 10, hj: 89})
const arr2 = IWithLength([4,6,6])
